package com.ht.power3d.vmap;

import com.ht.power3d.geop.TopoInfoReader;
import com.ht.power3d.geop.GeoGL;

import java.util.List;
import java.util.ArrayList;
import java.util.Random;

import com.ht.visiomodel.TopoInfo;

import javax.xml.bind.JAXBException;

/**
 * @author SU Xinyi
 * @since 2009-5-22
 */
public class DataPointsLoaderImpl2 implements DataPointsLoader{
    public List<DataPoint> getDataPoints() {
        List<DataPoint> dataPoints = new ArrayList<DataPoint>();
        TopoInfoReader dataReader = new TopoInfoReader();
        TopoInfo topoInfo = null;
        try {
            topoInfo = dataReader.readTopoInfo(DataPointsLoaderImpl2.class.getResourceAsStream("/topo/node.xml"));
        } catch (JAXBException e) {
            e.printStackTrace();
        }
        float minx = 9999;
        float maxx = 0;
        float miny = 9999;
        float maxy = 0;
        Random rand = new Random(System.currentTimeMillis());
        for(TopoInfo.Nodes.Node node : topoInfo.getNodes().getNode()){
            float x = (float) node.getGraphicalInfo().getAbscissa();
            float y = (float) (GeoGL.FRAME_HEIGHT_3D - node.getGraphicalInfo().getOrdinate());
            //float y = (float) node.getGraphicalInfo().getOrdinate();

            if(x>maxx){
                maxx = x;
            }
            if(x<minx){
                minx = x;
            }
            if(y>maxy){
                maxy = y;
            }
            if(y<miny){
                miny = y;
            }
            DataPoint newDataPoint = new DataPoint(x, y);
            newDataPoint.setValue((float) (rand.nextDouble()*0.01+1.0));
            dataPoints.add(newDataPoint);
        }
        return dataPoints;
    }
}